using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace BBCoder {
	public class HTML_Helper {

		/// <summary>
		/// Allows HTML to be displayed as plain text.
		/// </summary>
		/// <param name="plainText">The plain text to display</param>
		/// <returns>Plain text with HTML special chars converted to HTML
		/// escape codes.</returns>
		public static string EscapeHTML(string plainText) {
			return plainText.Replace("&", "&amp;")
				.Replace("<", "&lt;")
				.Replace(">", "&gt;");
		}

		/// <summary>
		/// Converts HTML escape codes for &amp; &lt; and &gt; back into plain text.
		/// </summary>
		/// <param name="HTML">The HTML to convert back to plain text</param>
		/// <returns></returns>
		/// <remarks>Could possibly be extended later to convert _all_ HTML escape codes
		/// to plain text.</remarks>
		public static string UnEscapeHTML(string HTML) {
			return HTML.Replace("&gt;", ">")
				.Replace("&lt;", "<")
				.Replace("&amp;", "&");
		}

		/// <summary>
		/// Displays pre-formatted text as originally entered.
		/// </summary>
		/// <param name="plainText">The pre-formatted text</param>
		/// <returns>HTML that displays text as plain text</returns>
		/// <remarks>This assumes \n's have already been converted</remarks>
		public static string PreFormatHTML(string plainText) {
			return plainText
				.Replace("  ", "&nbsp;&nbsp;").Replace("> ", ">&nbsp;");
		}
	}
}
